--知己知彼

local knownBothSkill = fk.CreateSkill{
    name = "known_both_skill",
}

knownBothSkill:addEffect("cardskill",{
    prompt = "#known_both_skill",
    can_use = Util.CanUse,
    target_num = 1,
    mod_target_filter = function(self, player, to_select, selected, card)
      local target = to_select
      return player ~= target and (not target:isKongcheng() or target.general == "anjiang" or target.deputyGeneral == "anjiang")
    end,
    target_filter = Util.CardTargetFilter,
    on_effect = function(self, room, effect)
      local player = effect.from
      local target = effect.to
      if target.dead or player.dead then return end
      local all_choices = {"known_both_main", "known_both_deputy", "known_both_hand"}
      local choices = table.clone(all_choices)
      if not target.deputyGeneral or target.deputyGeneral ~= "anjiang" then
        table.remove(choices, 2)
      end
      if target:isKongcheng() then
        table.remove(choices)
      end
      if target.general ~= "anjiang" then
        table.remove(choices, 1)
      end
      if #choices == 0 then return end
      local choice = room:askToChoice(player, {choices = choices, skill_name = "known_both", prompt = "#known_both-choice::"..target.id, cancelable = false, all_choices = all_choices})
      if choice == "known_both_hand" then
        room:viewCards(player, {cards = target:getCardIds("h"), skill_name = "known_both", prompt = "#known_both-hand::"..target.id})
          room:sendLog{
            type = "#know_hand",
            from = player.id,
            to = {target.id},
            toast = true,
          }
      else
        local general = choice == "known_both_main" and {target:getMark("__heg_general"), target.deputyGeneral, tostring(target.seat)} or {target.general, target:getMark("__heg_deputy"), tostring(target.seat)}
        room:askToCustomDialog(player, {skill_name = knownBothSkill.name, qml_path = "packages/ol_hegemony/qml/KnownBothBox.qml", extra_data = general})
        room:sendLog{
          type = "#WatchGeneral",
          from = player.id,
          toast = true,
          to = {target.id},
          arg = choice == "known_both_main" and "mainGeneral" or "deputyGeneral",
          arg2 = choice == "known_both_main" and target:getMark("__heg_general") or target:getMark("__heg_deputy"),
        }
     end
    end,
})

knownBothSkill:addTest(function (room, me)
  local card = Fk:cloneCard("known_both")
  local comp2 = room.players[2]
  FkTest.setNextReplies(me, {"known_both_main", "1", "known_both_deputy", "1", "known_both_hand"})
  FkTest.runInRoom(function()
    room:setPlayerProperty(comp2, "deputyGeneral", "zhouyu")
    comp2:hideGeneral(false)
    comp2:hideGeneral(true)
    room:obtainCard(comp2, 1)
    for _ = 1, 3 do
      room:useCard {
        from = me,
        tos = { comp2 },
        card = card,
      }
    end
  end)
end)

Fk:loadTranslationTable{
  ["known_both_skill"] = "知己知彼",
  ["#known_both_skill"] = "选择一名其他角色，观看其一张暗置的武将牌或其手牌",
  ["#known_both-choice"] = "知己知彼：选择对 %dest 执行的一项",
  ["known_both_main"] = "观看主将",
  ["known_both_deputy"] = "观看副将",
  ["known_both_hand"] = "观看手牌",
  ["#KnownBothGeneral"] = "观看 %1 武将",
  ["#known_both-hand"] = "知己知彼：观看%dest的手牌",
  ["#know_hand"] = "%from 观看了 %to 的 <b><font color='DeepPink'>手牌<b>",
  ["#know_general"] = "%from 观看了 %to 的 %arg",
  ["#WatchGeneral"] = "%from 观看了 %to 的 %arg",
}

return knownBothSkill